package com.study.studyfive.quartz.bindspringboot;

import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Slf4j
@Configuration
public class QuartzConfig {

    @Bean
    public void config() throws SchedulerException {
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();

        JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class)
                // 任务的唯一标识 key
                .withIdentity(JobKey.jobKey("job1"))
                // 带上任务的一些其他信息，方便后续处理使用
                .usingJobData(new JobDataMap() {{
                    put("key1", "value1");
                }})
                .build();
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity(TriggerKey.triggerKey("trigger1"))
                .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ? "))
                .build();
        scheduler.scheduleJob(jobDetail, trigger);

       // scheduler.start();

    }

}